package edu.qd.learn.newchapter.chapter02.exam01;

/**
 * 学生类
 *
 * @author 布衣
 */
public class Student {
    //只能我自己操作的名称
    private String name;
    public Student(String stuName) {
        name = stuName;
    }
    public void ball(Rule rule) {
        String ballName = rule.getName();
        System.out.println(name + "同学,正在打" + ballName);
        rule.play();
    }
    public static void main(String[] args) {
        Student s = new Student("卢禹彤");
        Rule basketball = new Rule() {
            private String ballName;
            @Override
            public void play() {
                System.out.println(ballName + "这是一项运动");
            }
            @Override
            public void setName(String name) {
                ballName = name;
            }
            @Override
            public String getName() {
                return ballName;
            }
        };
        basketball.setName("篮球");
        s.ball(basketball);
    }

}
